using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace ICP_MS.Plugin.Experiment;

public class ColorCntl : UserControl
{
	private IContainer components = null;

	private Label lblSymbol;

	private Panel lblColor;

	public string Symbol
	{
		get
		{
			return lblSymbol.Text;
		}
		set
		{
			lblSymbol.Text = value;
		}
	}

	public Color color
	{
		get
		{
			return lblColor.BackColor;
		}
		set
		{
			lblColor.BackColor = value;
		}
	}

	public event EventHandler ColorChanged;

	public ColorCntl(string label, Color c)
	{
		InitializeComponent();
		Symbol = label;
		color = c;
	}

	private void lblColor_MouseDoubleClick(object sender, MouseEventArgs e)
	{
		Color old = (sender as Panel).BackColor;
		Color newColor = GetNewcolor(old);
		if (newColor != old)
		{
			(sender as Panel).BackColor = newColor;
			if (this.ColorChanged != null)
			{
				this.ColorChanged(this, null);
			}
		}
	}

	private Color GetNewcolor(Color old)
	{
		Color newColor = old;
		ColorDialog dlg = new ColorDialog();
		dlg.Color = old;
		if (dlg.ShowDialog() == DialogResult.OK)
		{
			newColor = dlg.Color;
		}
		return newColor;
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.lblSymbol = new System.Windows.Forms.Label();
		this.lblColor = new System.Windows.Forms.Panel();
		base.SuspendLayout();
		this.lblSymbol.AutoSize = true;
		this.lblSymbol.Location = new System.Drawing.Point(9, 9);
		this.lblSymbol.Name = "lblSymbol";
		this.lblSymbol.Size = new System.Drawing.Size(41, 12);
		this.lblSymbol.TabIndex = 0;
		this.lblSymbol.Text = "label1";
		this.lblColor.Location = new System.Drawing.Point(62, 6);
		this.lblColor.Name = "lblColor";
		this.lblColor.Size = new System.Drawing.Size(58, 20);
		this.lblColor.TabIndex = 1;
		this.lblColor.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(lblColor_MouseDoubleClick);
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.Controls.Add(this.lblColor);
		base.Controls.Add(this.lblSymbol);
		base.Name = "ColorCntl";
		base.Size = new System.Drawing.Size(141, 32);
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
